/**
 * Copyright 2018-2020 stylefeng & fengshuonan (https://gitee.com/stylefeng)
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.mbl.base.core.aop;

import com.alibaba.fastjson.JSON;
import com.mbl.base.config.security.SecurityUser;
import com.mbl.base.core.modular.log.factory.LogTaskFactory;
import com.mbl.base.core.utils.UtilHttp;
import com.mbl.base.core.utils.UtilSecurity;
import com.mbl.base.modular.base.entity.Log;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;


/**
 * 日志记录
 *
 * @author fengshuonan
 * @date 2016年12月6日 下午8:48:30
 */
@Aspect
@Slf4j
@Component
public class LogAop {

    @Pointcut("execution(* com.mbl.base.modular.*.controller.*.*(..))")
    public void cutService() {
    }
    @Around("cutService()")
    public Object recordSysLog(ProceedingJoinPoint point) throws Throwable {
        //先执行业务
        Object result = point.proceed();
        try {
            handle(point, result);
        } catch (Exception e) {
        }
        return result;
    }

    private void handle(ProceedingJoinPoint point, Object result) throws Exception {
        LogTaskFactory.visitLog(JSON.toJSONString(result));
    }
}